<template>
  <div class="app-container">

    <u-page title="意见反馈">

      <u-filtered>
        <el-form :inline="true" :model="listQuery" class="search-form">
          <el-form-item label="卡号" prop="memberId">
            <el-input v-model="listQuery.memberId" placeholder="请输入卡号" clearable />
          </el-form-item>
          <el-form-item label="内容" prop="content">
            <el-input v-model="listQuery.content" placeholder="关键词搜索" clearable />
          </el-form-item>
          <el-form-item label="状态" prop="status">
            <el-select v-model="listQuery.status" placeholder="请选择状态" class="status" clearable>
              <el-option value="" label="全部" />
              <el-option :value="0" label="待处理" />
              <el-option :value="1" label="处理中" />
              <el-option :value="3" label="已完成" />
              <el-option :value="2" label="终止申请" />
            </el-select>
          </el-form-item>
          <el-form-item label="时间范围">
            <u-date-time-picker v-model="searchDate" @change="changeSearchDate" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="hdlFilter">搜索</el-button>
          </el-form-item>
          <el-form-item>
            <el-dropdown>
              <el-button type="primary">
                批量操作<i class="el-icon-arrow-down el-icon--right" />
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item :disabled="selectData.length===0" @click.native="hdlDel">批量删除</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </el-form-item>
        </el-form>
      </u-filtered>

      <u-table
        :data="list"
        :loading="listLoading"
        :options="listOptions"
        :columns="columns"
        :pagination.sync="listQuery"
        :fetch="hdlList"
        @selection-change="hdlSelectChange"
      >
        <template v-slot:right>
          <el-table-column label="操作" align="center" fixed="right">
            <template slot-scope="{ row }">
              <el-button type="text" @click="hdlEdit(row)">编辑</el-button>
              <el-button type="text" @click="hdlDelete(row.id, row.title)">删除</el-button>
            </template>
          </el-table-column>
        </template>
      </u-table>

    </u-page>

    <u-dialog :title="textMap[dialogStatus]" :show.sync="dialogFormVisible" @confirm="dialogStatus==='create'?hdlCreate():hdlUpdate()">
      <el-form ref="dialogForm" :rules="rules" :model="dataForm" label-width="60px">

        <el-descriptions :column="2" border direction="vertical">
          <el-descriptions-item :span="2" label="类型"> {{ dataForm.title }}</el-descriptions-item>
          <el-descriptions-item :span="2" label="卡号"> {{ dataForm.memberId }}</el-descriptions-item>
          <el-descriptions-item :span="2" label="反馈内容"> {{ dataForm.content }}</el-descriptions-item>

          <el-descriptions-item :span="2">
            <template slot="label">
              反馈截图
            </template>
            <template v-if="dataForm.thumb">
              <div class="uploader">
                <div v-for="(url,index) in dataForm.thumb.split(',')" :key="index" class="thumb">
                  <el-image :src="url" :preview-src-list="dataForm.thumb.split(',')" lazy class="image-preview" />
                </div>
              </div>

            </template>
          </el-descriptions-item>

          <el-descriptions-item :span="2" label="处理状态">
            <el-radio-group v-model="dataForm.status">
              <el-radio-button :label="0">待处理</el-radio-button>
              <el-radio-button :label="1">处理中</el-radio-button>
              <el-radio-button :label="2">终止</el-radio-button>
              <el-radio-button :label="3">已完成</el-radio-button>
            </el-radio-group>
          </el-descriptions-item>

          <el-descriptions-item :span="2" label="处理结果">
            <el-input v-model="dataForm.reply" type="textarea" placeholder="处理结果" clearable maxlength="500" show-word-limit />
          </el-descriptions-item>

        </el-descriptions>

      </el-form>
    </u-dialog>

  </div>
</template>
<script>

export default {
  data() {
    return {
      api: this.$u.api.PluginsFeedback,
      // 表格
      columns: [
        {
          prop: 'title',
          label: '类型'
        },
        {
          prop: 'memberId',
          label: '卡号'
        },
        {
          prop: 'content',
          label: '反馈内容'
        },
        {
          prop: 'createdAt',
          label: '反馈时间',
          timestamp: true
        },
        {
          prop: 'status',
          label: '状态',
          render: (h, params) => {
            const { status } = params.row
            if (status === 0) {
              return h('el-tag', { props: { type: 'danger' }}, '待处理')
            } else if (status === 1) {
              return h('el-tag', { props: { type: 'warning' }}, '处理中')
            } else if (status === 2) {
              return h('el-tag', { props: { type: 'info' }}, '终止')
            } else if (status === 3) {
              return h('el-tag', { props: { type: 'success' }}, '已完成')
            }
          }
        },
        {
          prop: 'updatedBy',
          label: '操作人'
        },
        {
          prop: 'updatedAt',
          label: '操作时间',
          formatter: (row) => {
            if (row.updatedBy) {
              return this.$u.timeFormat(row.updatedAt)
            }
          }
        },
        {
          prop: 'reply',
          label: '回复'
        }
      ],

      list: [],
      listLoading: false,
      listOptions: {
        mutiSelect: true, // boolean 是否多选
        stripe: true // boolean 斑马纹
      },
      listQuery: {
        pageNumber: 1,
        pageSize: 10,
        totalCount: 1,
        beginTime: '',
        endTime: '',
        name: '',
        mobile: '',
        status: ''
      },

      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '编辑反馈',
        create: '新增反馈'
      },
      dataForm: {},
      rules: {
        title: [
          { required: true, message: '请输入标题', trigger: ['blur'] }
        ],
        content: [
          { required: true, message: '请输入内容', trigger: ['blur'] }
        ]
      },
      // 删除选中数据
      selectData: []
    }
  },
  created() {
    this.hdlList()
  },
  methods: {
  }
}
</script>
<style lang="scss" scoped>
  .app-container{

    & >>> .el-drawer__body {
      overflow: auto;
    }

    .uploader{

      .thumb{
        display: inline-block;
        text-align: center;
        outline: none;
        background-color: #fbfdff;
        border: 1px dashed #c0ccda;
        border-radius: 6px;
        box-sizing: border-box;
        width: 120px;
        height: 120px;
        cursor: pointer;
        line-height: 120px;
        vertical-align: top;

        ::v-deep {
          .el-image {
            width: 100%;
            height: 100%;
            display: block;
            border-radius: 6px;
          }

          img{
            width: 100%;
            height: 100%;
            display: block;
            border-radius: 6px;
          }
        }
      }
    }

  }
</style>
